new Vue({
    el: '#app',
    data: {
        consignees: "",
        areaShow: false, //区域选择区块的显示和隐藏
        areas: [], //区域数据模板
        allAreas:[],//全部省份
        cityAreas:[],//全部市
        /*区域tab*/
        tabArea1: "",
        tabArea2: "请选择",
        tabArea3: "请选择",
        tabArea4: "请选择",
        /*区域tab的显示和隐藏*/
        areaTab1: true,
        areaTab2: false,
        areaTab3: false,
        areaTab4: false,
        /*点击区域tab时需要的parentCode*/
        parentCode2: "",
        parentCode3: "",
        /*点击区域tab时需要显示的areaName*/
        goName2: "",
        goName3: "",
        /*tab样式控制*/
        isCurr1: true,
        isCurr2: false,
        isCurr3: false,
        isCurr4: false,
        /*收获区域名称，省市乡镇分开*/
        provinceName: "请选择收货区域",
        cityName: "",
        countyName: "",
        villageName: "",
        /*获取选择的区域*/
        provinceId: window.historyPrivinceId,
        cityId: window.historyCityId,
        countyId: window.historyCountyId,
        villageId: window.historyVillageId,
        selectName:"北京"
    },
    mounted: function () {
        this.province("请选择");
        var that = this;
        $('body').on('click','.update',function () {
            //var curVal =  $(this).attr('data-val');
            that.areaShow = false;
            that.areas =[];
            that.allAreas =[];
            that.cityAreas=[];
            that.tabArea1= "请选择";
            that.tabArea2= "请选择";
            that.areaTab1=true;
            that.areaTab2=false;
            that.isCurr1 = true;
            that.isCurr2=false;
            that.provinceName = "请选择收货区域";
            that.cityName = "";
            that.provinceId= window.historyPrivinceId;
            that.cityId= window.historyCityId;
            that.province("请选择");
        })

        /*setTimeout(function () {
            $(".change_address")[0].click();
        },200)*/


        // Window.onload=function () {
        //     var radioObj = document.getElementsByClassName('change_address');
        //     for(var i=0;i<radioObj.length;i++){
        //         radioObj[i].onclick=function(){
        //             var curVal =  this.getAttribute('data-val');
        //             that.province(curVal);
        //         }
        //     }
        //     setTimeout(function () {
        //         radioObj[0].click();
        //     },200)
        // }


    },
    methods: {
        initAddress(){
            this.isCurr1 = true;
            this.isCurr2 = false;
            this.isCurr3 = false;
            this.isCurr4 = false;
            this.provinceName = "请选择收货区域";
            this.cityName = "";
            this.countyName = "";
            this.villageName = "";
            this.tabArea1 = "";
            this.tabArea2 = "请选择";
            this.tabArea3 = "请选择";
            this.tabArea4 = "请选择";
            this.areaTab1 = true;
            this.areaTab2 = false;
            this.areaTab3 = false;
            this.areaTab4 = false;
        },
        /*关闭选择框*/
        closeArea(){
            document.getElementById("provinceName").innerHTML = window.historyProvinceName;
            document.getElementById("cityName").innerHTML = window.historyCityName;
            document.getElementById("countyName").innerHTML = window.historyDistrictName;
            document.getElementById("villageName").innerHTML = window.historyStreetName;
            this.initAddress();
            this.province(this.selectName);
            this.areaShow = false;
            var vueBox = document.getElementById("vueBox");
            vueBox.style.display = "none";
            var notVueBox = document.getElementById("notVueBox");
            notVueBox.style.display = "block";
            window.updataGoodsList(window.historyPrivinceId);
        },
        /*点击弹出区域选择框*/
        isAreaShow() {
            this.areaShow = !this.areaShow;
            if(this.areaShow == false){
                document.getElementById("provinceName").innerHTML = window.historyProvinceName;
                document.getElementById("cityName").innerHTML = window.historyCityName;
                document.getElementById("countyName").innerHTML = window.historyDistrictName;
                document.getElementById("villageName").innerHTML = window.historyStreetName;
                var vueBox = document.getElementById("vueBox");
                vueBox.style.display = "none";
                var notVueBox = document.getElementById("notVueBox");
                notVueBox.style.display = "block";
                this.initAddress();
                this.province(this.selectName);
                window.updataGoodsList(window.historyPrivinceId);
            }else {
                var vueBox = document.getElementById("vueBox");
                vueBox.style.display = "block";
                var notVueBox = document.getElementById("notVueBox");
                notVueBox.style.display = "none";
            }
        },
        /*加载获取省份*/
        province(areaName) {

            var warhouseCode = $('#areaSelect option:selected').val();

            let that = this;
            $.ajax({
                type: "POST",
                //url:"http://192.168.0.32:7060/amembership/adminGetRegionAddress.jhtml",
                url: 'https://'+ window.location.host +'/api/admin/abaseservice/area/getWarehouseCoverAddressCascade',
                // url: root.replaceInter.replace_adminGetRegionAddress,
                cache: false,  //禁用缓存
                dataType: "json",
                data: {
                    warehouseCode: warhouseCode,
                },  //传入组装的参数
                success: function (response) {
                    //console.log(response);
                    if (response.errorCode == 0) {
                        console.log(response.data);
                        that.tabArea1 = areaName;
                        that.allAreas = response.data;
                        that.areas = response.data;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    // alert(XMLHttpRequest);
                }
            });
        },
        /*点击选择区域（省市县乡）*/
        getArea(level,areaName,areaId,warehouseCode,id) {

            //console.log(level,areaName,areaId,warehouseCode)
            switch(level){
                case 101:
                    for(let i=0;i<this.areas.length;i++){
                        if(this.areas[i].code==areaId&&this.areas[i].child_address_library.length!=0){
                            //有二级城市
                            this.areaTab2 = true;
                            this.isCurr1 = false;
                            this.isCurr2 = true;
                            this.tabArea1 = this.areas[i].name;
                            this.tabArea2 = "请选择";
                            this.provinceName = this.areas[i].name;
                           // this.provinceId = this.areas[i].code;
                            this.provinceId = this.areas[i].address_id;
                            this.cityAreas = this.areas[i].child_address_library;
                            this.areas = this.areas[i].child_address_library;
                        }else if(this.areas[i].code==areaId&&this.areas[i].child_address_library.length==0){
                            // 无二级
                            this.tabArea1 = areaName;
                            //this.tabArea2 = areaName;
                            this.warehouseCode = warehouseCode;
                            this.provinceName = this.areas[i].name;
                          //  this.provinceId = this.areas[i].code;
                            this.provinceId = this.areas[i].address_id;
                            //this.cityName = this.areas[i].name;
                            //this.cityId = this.areas[i].code;
                            this.areaDatas={
                                provinceName: this.areas[i].name,
                              //  provinceId: this.areas[i].code,
                                provinceId: this.areas[i].address_id,
                                cityName: this.areas[i].name,
                               // cityId: this.areas[i].code,
                                cityId: this.areas[i].address_id,
                                warehouseCode:warehouseCode
                            }
                            this.areaTab2 = false;
                            this.areaShow = false;
                        }
                    }
                    break;
                case 102:
                    this.warehouseCode = warehouseCode;
                    this.tabArea2 = areaName;
                    this.cityName = areaName;
                    this.cityId = id;
                    this.areaShow = false;
                    break;


                case 1:
                    this.isCurr1 = true;
                    this.isCurr2 = false;
                    this.areas = this.allAreas;
                    break;
                case 2:
                    this.isCurr1 = false;
                    this.isCurr2 = true;
                    this.areas = this.cityAreas;
                    this.areaShow = false;
                    break;
            }
        },
    },
});